package mrunit;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Mapper;

public class SMSCDRMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

	private Text status = new Text();

	private final static IntWritable addOne = new IntWritable(1);
	
	static enum CDRCounter {
		NoneCDR;
	}

	
	// 不建议在方法中使用全类名称：org.apache.hadoop.mapreduce.Mapper.Context
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

		// 655209;1;796764372490213;804422938115889;6
		String[] line = value.toString().split(";");
		if (Integer.parseInt(line[1]) == 1) {
			status.set(line[4]);
			context.write(status, addOne);
		}else{
			context.getCounter(CDRCounter.NoneCDR).increment(1);
		}

	}
}
